//
//  ZH_QQViewController.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/24.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_QQViewController.h"
#import "ZH_MallViewModel.h"
@interface ZH_QQViewController ()
@property (nonatomic,weak)UIImageView *iconImage;
@property (nonatomic,weak)UIView *lineView;
@property (nonatomic,weak)UITextField *textField;
@property (nonatomic,weak)UIView *lineViews;
@property (nonatomic,weak)UIButton *button;
@property (nonatomic,strong)ZH_MallViewModel *viewModel;
@end

@implementation ZH_QQViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    [self initUserInterface];
}
- (void)cleanUpData{
    [self setViewModel:nil];
}
- (void)initUserInterface{
    self.navigationItem.title = @"QQ号";
    self.view.backgroundColor = [UIColor whiteColor];
    [self.iconImage mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.view).offset(FITSCALE(45));
        make.left.equalTo(self.view).offset(FITSCALE(44));
        make.width.mas_equalTo(FITSCALE(18));
        make.height.mas_equalTo(FITSCALE(19));
    }];
    [self.lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.iconImage);
        make.width.mas_equalTo(FITSCALE(1));
        make.left.equalTo(self.iconImage.mas_right).offset(FITSCALE(20));
        make.height.mas_equalTo(FITSCALE(22));
    }];
    [self.textField mas_makeConstraints:^(MASConstraintMaker *make) {
        make.centerY.equalTo(self.lineView);
        make.left.equalTo(self.lineView.mas_right).offset(FITSCALE(11));
        make.right.equalTo(self.view).offset(FITSCALE(-22));
    }];
    [self.lineViews mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineView.mas_bottom).offset(FITSCALE(10));
        make.left.equalTo(self.view).offset(FITSCALE(22));
        make.right.equalTo(self.view).offset(FITSCALE(-22));
        make.height.mas_equalTo(FITSCALE(1));
    }];
    [self.button mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.lineViews.mas_bottom).offset(FITSCALE(93));
        make.left.equalTo(self.view).offset(FITSCALE(22));
        make.right.equalTo(self.view).offset(FITSCALE(-22));
        make.height.mas_equalTo(FITSCALE(46));
    }];
    
}
///输入框 回调 方法
- (void)textFieldDidEndEditing:(UITextField *)textField
{
    //    if(self.onEnterTextFieldBlock){
    //        self.onEnterTextFieldBlock(textField.text, textField.tag);
    //    }
    [self.viewModel.modifyParam setObject:textField.text forKey:@"data"];
}

-(BOOL)textFieldShouldReturn:(UITextField *)textField
{
    [self.textField endEditing:YES];
    return YES;
}
- (void)button:(UIButton *)btn{
    [self.viewModel.modifyParam setObject:@"2" forKey:@"type"];
    WEAKSelf;
    [self.viewModel modifyResultBlock:^(NSString *code, NSString *message, id data) {
        if ([code isEqualToString:@"0"]) {
            [weakSelf.navigationController popViewControllerAnimated:YES];
        }
        else{
            [weakSelf showHint:message];
        }
    }];
}
#pragma mark - getter,setter
- (UIImageView *)iconImage{
    if (!_iconImage) {
        UIImageView *image = [UIImageView createImageViewWithName:@"icon_qq1"];
        [self.view addSubview:_iconImage = image];
    }
    return _iconImage;
}
- (UIView *)lineView{
    if (!_lineView) {
        UIView *view = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#CCCCCC"]];
        [self.view addSubview:_lineView = view];
    }
    return _lineView;
}
- (UITextField *)textField
{
    if(!_textField){
        UITextField *textField = [UITextField createTextFieldWithPlaceholder:@"请输入QQ号" placeholderColor:kFontColorGray delegateTarget:self];
        textField.borderStyle = UITextBorderStyleNone;
        textField.font = kFontSize_28;
        textField.textAlignment = NSTextAlignmentLeft;
        textField.returnKeyType = UIReturnKeyDone;
        [textField setTextColor:kFontColorBlack];
        [self.view addSubview:_textField = textField];
    }
    return _textField;
}
- (UIView *)lineViews{
    if (!_lineViews) {
        UIView *view = [UIView createViewWithBackgroundColor:[UIColor colorWithHexString:@"#CCCCCC"]];
        [self.view addSubview:_lineViews = view];
    }
    return _lineViews;
}
- (UIButton *)button{
    if (!_button) {
        UIButton *button = [UIButton createNoBgButtonWithTitle:@"下一步" target:self action:@selector(button:)];
        button.backgroundColor = [UIColor colorWithHexString:@"#00C9AE"] ;
        [button setTitleColor:kFontColorWhite forState:UIControlStateNormal];
        button.layer.cornerRadius = FITSCALE(22);
        button.layer.masksToBounds = YES;
        button.clipsToBounds = YES;
        button.titleLabel.font = kFontSize_34;
        [self.view addSubview:_button = button];
    }
    return _button;
}
- (ZH_MallViewModel *)viewModel{
    if (!_viewModel) {
        _viewModel = [[ZH_MallViewModel alloc] init];
    }
    return _viewModel;
}
@end
